import { AddLevel } from '@/apis/user';
import { Modal, Form, Input, InputNumber, Radio } from 'antd';
import Style from '../styles/user.less'

type Props = {
    visiable: boolean,
    close: (state: boolean) => void
}

const AddUserLevel = (props: Props) => {
    const [form] = Form.useForm()
    const { visiable, close } = props;

    const handleOk = async () => {
        const value = form.getFieldsValue()
        console.log(value);
        const res: any = await AddLevel(value)
        console.log(res);
        close(false)
    };

    const handleCancel = () => {
        close(false)
    };

    return (
        <Modal title="添加用户等级" open={visiable} destroyOnClose={true}
            onOk={handleOk} onCancel={handleCancel} width={700}>
            <Form preserve={false} form={form} >
                <Form.Item name="name" label="等级名称" labelCol={{ span: 3 }} rules={[{ required: true }]}>
                    <Input />
                </Form.Item>

                <div className={Style.levelbox}>
                    <Form.Item name="grade" label="等级" rules={[{ required: true }]}>
                        <InputNumber />
                    </Form.Item>
                    <Form.Item name="discount" label="享受折扣" rules={[{ required: true }]}>
                        <InputNumber />
                    </Form.Item>
                    <Form.Item name="exp_num" label="解锁需经验值达到" rules={[{ required: true }]}>
                        <InputNumber />
                    </Form.Item>
                </div>

                <Form.Item name="icon" label="图标" labelCol={{ span: 3 }} >
                    <Input />
                </Form.Item>

                <Form.Item name="image" label="等级背景" labelCol={{ span: 3 }} >
                    <Input />
                </Form.Item>

                <Form.Item name="is_show" label="是否显示" labelCol={{ span: 3 }} >
                    <Radio.Group>
                        <Radio value="1">是</Radio>
                        <Radio value="0">否</Radio>
                    </Radio.Group>
                </Form.Item>

                <Form.Item name="explain" label="等级说明" labelCol={{ span: 3 }} >
                    <Input />
                </Form.Item>

            </Form>
        </Modal>
    )
}

export default AddUserLevel